package com.heima.wemedia.controller.v1;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.heima.model.wemedia.pojos.WmNews;
import com.heima.wemedia.service.WmChannelService;
import com.heima.wemedia.service.WmNewsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 自媒体图文内容信息表 前端控制器
 * </p>
 *
 * @author itheima
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {
    @Autowired
    private WmChannelService wmChannelService;

    @Autowired
    private WmNewsService  wmNewsService;

    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody WmNewsDto wmNewsDto){

        wmNewsService.submit(wmNewsDto);

        return ResponseResult.okResult("添加成功");
    }
    @PostMapping("/list")
    public PageResponseResult findList(@RequestBody WmNewsPageReqDto wmNewsPageReqDto){
        Page wmNewsPage = wmNewsService.findList(wmNewsPageReqDto);
        return new PageResponseResult(wmNewsPage);
    }
    @GetMapping("/one/{id}")
    public ResponseResult findById(@PathVariable("id") Integer id){
        WmNews byId = wmNewsService.getById(id);
        return ResponseResult.okResult(byId);
    }

    @GetMapping("/del_news/{id}")
    public ResponseResult delNews(@PathVariable("id") Integer id){
        return wmNewsService.delNews(id);
    }


    @PostMapping("/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto wmNewsDto){
        return wmNewsService.downOrUp(wmNewsDto);
    }
}
